<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\App;

class DevCors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (!App::environment('local')) {
            return $next($request);
        }
        $resp = $next($request);
        $resp->headers->add([
            'Access-Control-Allow-Origin'=>'*',
            'Access-Control-Allow-Methods'=>'POST,GET,OPTIONS,PUT,DELETE',
        ]);
        return $resp;
    }
}
